package com.huangguolin.cloud.api.role.control;

import com.huangguolin.cloud.api.role.entity.ApiRoleSearchEntity;
import com.huangguolin.cloud.api.role.service.ApiRoleService;
import com.huangguolin.cloud.mybatis.entity.PtRoleEntity;
import com.huangguolin.cloud.mybatis.flexigrid.PagingEntity;
import com.huangguolin.cloud.mybatis.ztree.ChildTree;
import com.huangguolin.cloud.spring.control.BaseController;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/role")
public class ApiRoleController extends BaseController {
    @Resource
    private ApiRoleService apiRoleService;
    private Logger logger = LogManager.getLogger(this.getClass());
    @RequestMapping("/queryRoleList")
    public List<PtRoleEntity> queryRoleList(PagingEntity paging, ApiRoleSearchEntity entity){

        List<PtRoleEntity> list = apiRoleService.queryRoleList(entity,paging);
        return list;
    }
    @RequestMapping("/queryRoleTotal")
    public String queryRoleTotal(ApiRoleSearchEntity entity){

        Integer total = apiRoleService.queryRoleTotal(entity);
        return totalJSON(total);
    }

    @RequestMapping("/queryMenuTree")
    public List<ChildTree> queryMenuTree(){
        List<ChildTree> list = apiRoleService.queryMenuTree();
        return list;
    }

    @RequestMapping("/saveMenRefRole")
    public String saveMenRefRole(@RequestParam("roleUuids") String roleUuids, @RequestParam("menuCheckIds")String menuCheckIds, @RequestParam("menuHalfIds")String menuHalfIds){
        logger.info("roleUuids:" + roleUuids+"menuCheckIds:" + menuCheckIds+"menuHalfIds:" + menuHalfIds);
        apiRoleService.saveMenRefRole(roleUuids,menuCheckIds,menuHalfIds);
        return successJSON("role.allow.menu.success");
    }


    @RequestMapping("/queryAllowMenuRst")
    public List<String> queryAllowMenuRst(@RequestParam("roleUuid") String roleUuid){
        logger.info("roleUuid:" + roleUuid);
        List<String> menuList = apiRoleService.queryAllowMenuRst(roleUuid);
        return menuList;
    }
}
